package login

import (
	"context"
	"database/sql"
	v1 "donkey-admin/api/menu/v1"
	"donkey-admin/internal/dao"
	"donkey-admin/internal/model/entity"
	"errors"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sAuthMenu) AuthMenuGetAll(ctx context.Context, req *v1.MenuGetAllReq) (res *v1.MenuGetAllRes, err error) {

	var menu []entity.SysMenu
	err = dao.SysMenu.Ctx(ctx).Where("menu_parent_id", nil).WhereOr("menu_parent_id", "").
		With(entity.SysMenu{}).Order("menu_order asc").Scan(&menu)
	if err != nil && errors.Is(err, sql.ErrNoRows) {
		g.Log().Error(ctx, err)
		return nil, err
	}

	return &v1.MenuGetAllRes{
		MenuList: menu,
	}, nil
}
